﻿using Microsoft.Xna.Framework;

namespace Brain
{
    public static class Vector2Util
    {
        public static int CenterVector2X(Vector2 vector, int ViewWidth)
        {
            int ViewWidthOver2 = ViewWidth / 2;
            int WidthRectangleOver2 = (int)(vector.X / 2);
            return ViewWidthOver2 - WidthRectangleOver2;
        }
        public static int CenterVector2Y(Vector2 vector, int ViewHeight)
        {
            int ViewWidthOver2 = ViewHeight / 2;
            int WidthRectangleOver2 = (int)(vector.Y / 2);
            return ViewWidthOver2 - WidthRectangleOver2;
        }
        public static Vector2 CenterVector2(Vector2 vector, int ViewWidth, int ViewHeight)
        {
            return new Vector2(CenterVector2X(vector, ViewWidth),
                                CenterVector2Y(vector, ViewHeight));
        }

        private static Vector2 half = new Vector2(0.5f);

        public static Vector2 Half
        {
            get { return half; }
        }

        /// <summary>
        /// Don't let the Vector2 pass the value
        /// </summary>
        /// <param name="vector"></param>
        /// <param name="minX"></param>
        /// <param name="maxX"></param>
        /// <param name="minY"></param>
        /// <param name="maxY"></param>
        /// <returns></returns>
        public static Vector2 Clamp(Vector2 vector, float minX, float maxX,
            float minY, float maxY)
        {
            return new Vector2(FloatUtil.Clamp(vector.X, minX, maxX),
                FloatUtil.Clamp(vector.Y, minY, maxY));
        }

        /// <summary>
        /// Linear interpolates between a value to another
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static Vector2 Lerp(Vector2 first, Vector2 second, float amount)
        {
            return new Vector2(FloatUtil.Lerp(first.X, second.X, amount),
                FloatUtil.Lerp(first.Y, second.Y, amount));
        }
    }
}
